//
//  LivingViewController.m
//  ExploreWorld
//
//  Created by dlios on 15/7/16.
//  Copyright (c) 2015年 chenlin. All rights reserved.
//

#import "LivingViewController.h"

@interface LivingViewController ()

@end

@implementation LivingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)dealloc
{
    [self.url release];
    [super dealloc];
}


- (void)loadView
{
    [super loadView];
    [self createLivingViewWithstrForPlay:self.url];
}


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
      }
    return self;
}



- (void)createLivingViewWithstrForPlay:(NSString *)strForPlay
{

    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(M_PI / 2);
    self.streamPlayer.view.transform = landscapeTransform;
    self.streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:strForPlay]];
    [self.streamPlayer.view setFrame:self.view.bounds];
    self.streamPlayer.controlStyle = MPMovieControlStyleEmbedded;
    [self.streamPlayer.view setFrame:[UIScreen mainScreen].bounds ];
    [self.view addSubview: self.streamPlayer.view];
    [self.streamPlayer play];
       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.streamPlayer];
//    UIButton *b = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 40)];
//    [b setTitle:@"完成" forState:UIControlStateNormal];
//    [b setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [b setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
//    [self.streamPlayer.view addSubview:b];
    
    
    
 }

- (void)myMovieFinishedCallback:(id)sender
{
     
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}



@end
